﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Chinaer.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string loginName = this.txtUserName.Text.Trim();
            string loginPassword = this.txtPassword.Text.Trim();
            DTO.ShangJiaDTO shangJiaDTO = CommonService.GetChinaerService.LoginShangJiaByNameAndPassword(loginName, loginPassword);
            if (shangJiaDTO.LoginStatus == Chinaer.Core.BaseCore.LoginStatus.UserNameIsNull)
            {
                Response.Write("用户名为空");
                return;
            }
            else if (shangJiaDTO.LoginStatus == Chinaer.Core.BaseCore.LoginStatus.PasswordIsNull)
            {
                Response.Write("密码为空");
                return;
            }
            else if (shangJiaDTO.LoginStatus == Chinaer.Core.BaseCore.LoginStatus.Success)
            {
                Response.Write("登陆成功");
                Session["apiToken"] = shangJiaDTO.ApiToken;
                Session["shangjiaid"] = shangJiaDTO.ID;
                Response.Redirect("index.aspx");
            }

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            DTO.ShangJiaDTO shangJiaDTO = new DTO.ShangJiaDTO()
            {
                LoginName = this.txtUserName.Text.Trim(),
                LoginPassword = this.txtPassword.Text.Trim()
            };
            var result = CommonService.GetChinaerService.RegisterShangJia(shangJiaDTO);
            if (result.Success == true)
            {
                Response.Write("注册成功");
                                
            }
            else
            {
                if (result.LoginStatus == Chinaer.Core.BaseCore.LoginStatus.UserNameIsNull)
                {
                    Response.Write("用户名为空");
                }
            }


        }
    }
}